package com.github.data_manage.dao

import com.github.data_manage.domain.po.FundPerson
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query

/**
 *@author CHN
 *@since 2024-08-10 14:48
 */
interface FundPersonDao : BaseDao<FundPerson> {

    fun findAllByFundId(fundId: Int): List<FundPerson>

    fun deleteAllByFundIdEqualsAndIdNotIn(fundId: Int, id: Collection<Int>): Int?

    fun findAllByPersonIdEquals(id: Int): List<FundPerson>

    @Modifying
    @Query("update FundPerson set name = :name , englishName = :englishName where personId = :personId")
    fun updatePersonNameById(personId: Int, name: String, englishName: String?)

    fun deleteAllByPersonIdEquals(personId: Int)

    @Modifying
    @Query("update FundPerson set position = :position where personId = :personId and fundId in (select distinct fundId from Fund where companyId= :companyId)")
    fun updatePersonPositionByPersonIdAndCompanyId(personId: Int, companyId: Int, position: String?)

    fun deleteAllByFundId(fundId: Int)
}